<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
					<el-input v-model="filters.keyword" placeholder="关键字"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="getList">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="messageList" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
			<el-table-column type="index" label="序号" width="70">
			</el-table-column>
			<el-table-column prop="title" label="标题" min-width="200" sortable>
			</el-table-column>
			<el-table-column prop="typeName" label="文章类型" min-width="120" sortable>
			</el-table-column>
			<el-table-column prop="updateTime" label="更新时间" min-width="170" sortable>
			</el-table-column>
			<el-table-column label="操作" min-width="70">
				<template scope="scope">
					<el-button size="small" type="info" @click="changeState(scope.$index, scope.row)" v-if="scope.row.ignore">启用</el-button>
					<el-button type="danger" size="small" @click="changeState(scope.$index, scope.row)" v-else>屏蔽</el-button>
				</template>
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="pageSize" :total="total" style="float:right;">
			</el-pagination>
		</el-col>
	</section>
</template>

<script>
	import util from '../../common/js/util'
	//import NProgress from 'nprogress'
	import { getInfoList , changeInfoState } from '../../api/api';
	export default {
		data() {
			return {
				filters: {
					keyword:"",
				},
				messageList: [],
				total: 0,
				page: 1,
				pageSize:50,
				listLoading: false,
				sels: [],//列表选中列

				editFormVisible: false,//编辑界面是否显示
				editLoading: false,
				editFormRules: {
					name: [
						{ required: true, message: '请输入姓名', trigger: 'blur' }
					]
				},
				//编辑界面数据
				editForm: {
					appName:'',
					eventTypeName:'',
					eventId:'',
					describe:'',
					remarks:'',
				},

				addFormVisible: false,//新增界面是否显示
				addLoading: false,
				addFormRules: {
					name: [
						{ required: true, message: '请输入姓名', trigger: 'blur' }
					]
				},
				//新增界面数据
				addForm: {
					list:[
						{
							eventTypeName:'',
							eventId:'',
							describe:'',
							remarks:'',
						}	
					]
				}

			}
		},
		methods: {
			handleCurrentChange(val) {
				this.page = val;
				this.getList();
			},
			//获取信息流列表
			getList() {
				let para = {
					userId:"bigdick",
				};
				this.listLoading = true;
				//NProgress.start();
				getInfoList(para).then((res) => {
					console.log(res.data.data)
					this.total = res.data.data.total;
					this.messageList = res.data.data.map(item=>{
						return Object.assign({},item,{
							createTime:util.formatDate.format(new Date(item.insertTime), 'yyyy-MM-dd hh:mm:ss'),
							updateTime:util.formatDate.format(new Date(item.updateTime), 'yyyy-MM-dd hh:mm:ss'),
						})
					});
					this.listLoading = false;
					//NProgress.done();
				});
			},
			//屏蔽启用信息流
			changeState(index,row){
				let startInfo = row.ignore?"确定要启用该文章吗？":"确定要屏蔽该文章吗？";
				let endInfo = row.ignore?"启用成功":"屏蔽成功";
				this.$confirm(startInfo, '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					//NProgress.start();
					let para = { 
						id: row.id,
						userId:"bigdick",
						operation:!row.ignore,
					};
					changeInfoState(para).then((res) => {
						this.listLoading = false;
						//NProgress.done();
						this.$message({
							message: endInfo,
							type: 'success'
						});
						this.getList();
					});
				}).catch(() => {

				});
			},	
			selsChange: function (sels) {
				this.sels = sels;
			},
		},
		mounted() {
			this.getList();
		}
	}

</script>

<style scoped>

</style>